//页面加载完成事件
$.MvcSheet.Loaded = function () {
    console.log("111");
    queryXsdb();
    setLanguage();

}

// 销售代表
function queryXsdb() {

    let mode = getUrlParam("Mode");
    
    if (("originate" == mode || "work" == mode ) && $.MvcSheetUI.ActivityCode == "Activity2" ) {
        var loginCode = $.MvcSheetUI.SheetInfo.UserCode;

        var param = '{"ADYHM":"' + loginCode + '"}';
        $.ajax({
            url: $.MvcSheetUI.PortalRoot + "/RunBizQuery/GetGridData",
            data: {
                "schemaCode": "ZXSDBX3",
                "queryCode": "queryXSDBsByLoginCode",
                "FilterStr": param,
                "PageIndex": 1,
                "PageSize": 20
            },
            dataType: "json",
            async: true,
            success: function (data) {
                if (data) {
                    if (data.Total && data.Total > 0) {
                        $.MvcSheetUI.SetControlValue("REP_0_XS", data.Rows[0].MC);
                        $.MvcSheetUI.SetControlValue("REP_0", data.Rows[0].BM);
                        queryTjz();
                    }
                }
            }
        });
    }


}



let getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name.toLocaleLowerCase() + "=([^&]*)(&|$)");
    var r = window.location.search.replace("__", "&").substr(1).toLocaleLowerCase().match(reg);
    if (r != null) return unescape(r[2]); return null;
}

// 隐藏贸易类型
// {CUR} != 'CNY' && {CUR}!='HKD'
function hideMylx(){
    var  comment = $.MvcSheetUI.GetControlValue("CUR");
    if(comment != 'CNY' && comment!='HKD'){
        $.MvcSheetUI.GetElement("YTRADTPY_XS").parent().show();

    }else{
        $.MvcSheetUI.GetElement("YTRADTPY_XS").parent().hide();
        $.MvcSheetUI.SetControlValue("YTRADTPY_XS","");
        $.MvcSheetUI.SetControlValue("YTRADTPY","");
        $.MvcSheetUI.SetControlValue("YTRADTPYDES","");
    }
}


function queryTjz() {
    var xsdbbm = $.MvcSheetUI.GetControlValue("REP_0");


    if (!xsdbbm || $.MvcSheetUI.GetControlValue("TSCCOD_0_XS")) return false;

    var param = '{"BM":"' + xsdbbm + '"}';
    $.ajax({
        url: $.MvcSheetUI.PortalRoot + "/RunBizQuery/GetGridData",
        data: {
            "schemaCode": "ZKHTJZX31",
            "queryCode": "ZKHTJZX31",
            "FilterStr": param,
            "PageIndex": 1,
            "PageSize": 20
        },
        dataType: "json",
        async: true,
        success: function (data) {
            if (data) {
                if (data.Total && data.Total > 0) {
                    $.MvcSheetUI.SetControlValue("TSCCOD_0_XS", data.Rows[0].KHTJZ1);
                    $.MvcSheetUI.SetControlValue("TSCCOD_1_XS", data.Rows[0].KHTJZ2);
                    $.MvcSheetUI.SetControlValue("TSCCOD_2_XS", data.Rows[0].KHTJZ3);
                    $.MvcSheetUI.SetControlValue("TSCCOD_3_XS", data.Rows[0].KHTJZ4);
                    $.MvcSheetUI.SetControlValue("TSCCOD_4_XS", data.Rows[0].KHTJZ5);
                    $.MvcSheetUI.SetControlValue("TSCCOD_0", data.Rows[0].KHTJZBM1);
                    $.MvcSheetUI.SetControlValue("TSCCOD_1", data.Rows[0].KHTJZBM2);
                    $.MvcSheetUI.SetControlValue("TSCCOD_2", data.Rows[0].KHTJZBM3);
                    $.MvcSheetUI.SetControlValue("TSCCOD_3", data.Rows[0].KHTJZBM4);
                    $.MvcSheetUI.SetControlValue("TSCCOD_4", data.Rows[0].KHTJZBM5);
                }
            }
        }
    });
}

//设置语言
function setLanguage() {

    var languagesMap = {"en_us": "EN_US", "zh_cn": "ZH_CN", "zh_tw": "ZH_TW"};
    var languVal = $.MvcSheetUI.SheetInfo.Language;

    $.MvcSheetUI.SetControlValue("CHANGELANG", languagesMap[languVal]);
    if(!$.MvcSheetUI.GetControlValue("CHANGELANG")){
        $.MvcSheetUI.SetControlValue("CHANGELANG", languagesMap["zh_cn"]);
    }

}
//依赖清空
function dependenceClean(fiel1,fiel2){
    try {
        $.MvcSheetUI.SetControlValue(fiel1,"");
        $.MvcSheetUI.SetControlValue(fiel2,"");
    }catch(e){
        console.log(e);
    }
}